package com.reremouse.servlet;

import com.reremouse.util.SpringHelper;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

public class ShowImage
        extends HttpServlet {
    public void destroy() {
        super.destroy();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        FileInputStream is = null;

        String id = request.getParameter("id");
        if (id != null) {
            String relativePath = SpringHelper.getSpringBean("relativeDir").toString() + id + ".jpg";

            String path = request.getServletContext().getRealPath(relativePath);
            File fff = new File(path);
            if (fff.exists()) {
                System.out.println(relativePath);

                RequestDispatcher rd = getServletContext().getRequestDispatcher("/" + relativePath);
                rd.forward(request, response);
            } else {
                RequestDispatcher rd = getServletContext().getRequestDispatcher("/resources/sys/default.jpg");
                rd.forward(request, response);
            }
        }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
        out.println("  <BODY>");
        out.print("    This is ");
        out.print(getClass());
        out.println(", using the POST method");
        out.println("  </BODY>");
        out.println("</HTML>");
        out.flush();
        out.close();
    }

    public void init()
            throws ServletException {
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.servlet.ShowImage

 * JD-Core Version:    0.7.0.1

 */